Skip to content

Reject shrinking disk during YAML validation #3596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

songponssw
Copy link
Contributor

I wish we would detect the attempt to downsize the disk size, and then reject the change as invalid, but that can be a separate PR.

As @jandubois suggested in #3533.

Currently, rejecting shrinking disk size happens during instance startup.
This PR adds validation earlier during YAML validation.
The function compares values between the new config and the latest config YAML files to reject disk size shrinking during validation.

@AkihiroSuda AkihiroSuda requested a review from Copilot May 31, 2025 11:41
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements early YAML validation to reject configurations that attempt to shrink the disk size rather than waiting until instance startup.

  • Added a ValidateYAMLAgainstLatest function that compares disk sizes from the new and latest YAML configurations.
  • Integrated the new validation into the limactl edit flow to save and report rejected configurations.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/limayaml/validate.go Added a YAML validation function to prevent disk size shrinking.
cmd/limactl/edit.go Integrated validation into the edit command and added a function to handle rejected YAML.

@songponssw songponssw force-pushed the reject-shrinking-disk branch 2 times, most recently from 4532c86 to 4f4a7c1 Compare June 18, 2025 16:55
@songponssw
Copy link
Contributor Author

The disk value can be nil when editing some YAML file.
For example, the editing kernel and initrd location in hack/inject-cmdline-to-template.sh.

@songponssw songponssw requested a review from AkihiroSuda June 19, 2025 00:06
@AkihiroSuda AkihiroSuda added this to the v1.1.2 milestone Jun 19, 2025
@songponssw songponssw marked this pull request as ready for review June 19, 2025 07:10
@AkihiroSuda AkihiroSuda requested a review from jandubois June 19, 2025 08:38
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, but there is some nitpicking I think should be addressed.

@songponssw songponssw force-pushed the reject-shrinking-disk branch from ecf31d3 to bbb1a66 Compare June 21, 2025 09:37
@AkihiroSuda
Copy link
Member

Please squash and sign off the commits

@songponssw
Copy link
Contributor Author

Got it! However, I noticed some unexpected behavior when no disk size is specified.

The generated YAML doesn't include the disk field, causing this function to return nil.
However, the disk shrinking is still rejected later when preparing the disk image.

I'm not sure whether we should inject the default disk size into the YAML when creating the new instance, or handle it another way.

Signed-off-by: Songpon Srisawai <songpon.ssw@gmail.com>
Co-authored-by: Jan Dubois <jan@jandubois.com>
@songponssw songponssw force-pushed the reject-shrinking-disk branch from bbb1a66 to 4ef46c4 Compare June 21, 2025 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants